package com.kyzh.core.activities

import android.os.Bundle
import com.gushenge.core.base.activity.BaseActivity
import com.gushenge.core.dao.MMKVConsts
import com.gushenge.core.impls.UserImpl
import com.gushenge.core.listeners.ResultListener
import com.kyzh.core.R
import com.gushenge.core.toast
import kotlinx.android.synthetic.main.act_modifypassword.*
import kotlinx.android.synthetic.main.titlebar.*

/**
 * Created by Administrator on 2017/9/25 0025.
 */

class ModifPasswordActivity : BaseActivity() {


    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.act_modifypassword)
        initUI()
    }

    private fun initUI() {
        tvTitle.text = getString(R.string.changePassword)
        close.setOnClickListener {finish()}
        commit.setOnClickListener {
            val oldPwS = old_pw.text.toString().trim()
            val newPwS = new_pw.text.toString().trim()
            val vePwS = repw.text.toString().trim()
            when{
                oldPwS.length<6 ->getString(R.string.passwordLessSix).toast()
                newPwS.length<6 ->getString(R.string.passwordLessSix).toast()
                vePwS.length<6 ->getString(R.string.passwordLessSix).toast()
                newPwS != vePwS -> getString(R.string.passwordNotMatch).toast()
                oldPwS.equals(newPwS) -> getString(R.string.passwordNotEquals).toast()
                else-> UserImpl.changePassword(oldPwS,newPwS,vePwS,object : ResultListener {
                    override fun success(bean: Any) {
                        bean.toast()
                        MMKVConsts.uid = ""
                        finish()
                    }

                    override fun error(error: String) {
                        error.toast()
                    }
                })

            }
        }
    }
}
